<template>
	<div class="query">
		<div class="tab clear">
			<div class="tab_btn fl" :class="{'active':todayType == 'mz'}" @click="tab('mz')">门诊</div>
			<div class="tab_btn fl" :class="{'active':todayType == 'zy'}" @click="tab('zy')">住院</div>
		</div>
		<div class="check">
			<div class="c_left">条件搜索栏</div>
			<div class="c_right">
				<div class="clear">
					<div class="fl">
						<span class="c_tip">查询方式</span>
						 <el-radio-group v-model="radio">
						    <el-radio :label="1">按科室</el-radio>
						    <el-radio :label="2">按医生</el-radio>
						    <el-radio :label="3">按药品</el-radio>
							<el-radio :label="4">按药师</el-radio>
						  </el-radio-group>
					</div>
					<div class="fl" v-if="radio == 1">
						<span class="c_tip">科室</span>
						<input type="text" class="c_input c_search" v-model="zd_dept_names" placeholder="请输入科室" readonly="readonly">
						<input type="hidden" class="c_input" v-model="zd_dept_codes">
						<i class="c_searchbtn" @click="selectPop('科室')">选择</i>
					</div>
					<div class="fl" v-if="radio == 2">
						<span class="c_tip">医生</span>
						<input type="text" class="c_input c_search" v-model="zd_doc_names" placeholder="请输入药品" readonly="readonly">
						<input type="hidden" class="c_input c_search" v-model="zd_doc_codes">
						<i class="c_searchbtn" @click="selectPop('医生')">选择</i>
					</div>
					<div class="fl" v-if="radio == 3">
						<span class="c_tip">药品</span>
						<input type="text" class="c_input c_search" v-model="zd_drug_names" placeholder="请输入药品" readonly="readonly">
						<input type="hidden" class="c_input c_search" v-model="zd_drug_codes">
						<i class="c_searchbtn"  @click="selectPop('药品')">选择</i>
					</div>
					<div class="fl" v-if="radio == 4">
						<span class="c_tip">药师</span>
						<input type="text" class="c_input c_search" v-model="zd_phr_names" placeholder="请输入药师" readonly="readonly">
						<input type="hidden" class="c_input c_search" v-model="zd_phr_codes">
						<i class="c_searchbtn"  @click="selectPop('药师')">选择</i>
					</div>
					<div class="clear"></div>
					<div class="fl">
						<span class="c_tip">开始时间</span>
						<el-date-picker
							v-model="starttime"
							type="date"
							placeholder="选择日期"
							class="c_select">
						</el-date-picker>
					</div>
					<div class="fl">
						<span class="c_tip">结束时间</span>
						<el-date-picker
							v-model="endtime"
							type="date"
							placeholder="选择日期"
							class="c_select">
						</el-date-picker>
					</div>
					<div class="fl" style="margin-left:65px;">
						<el-button type="danger" class="btn_clear" @click="searchFun">搜索</el-button>
						<el-button type="primary" class="btn_clear" @click="exportFun">导出XLS</el-button>
					</div>
				</div>
			</div>
		</div>
		<div class="list_tip clear">
			<!-- <span class="fl">数据管理列表</span> -->
		</div>
		<div class="table_box">
			<Bluetable :tHead="tHead" :tData="tableData"></Bluetable>
			<pagination :total="query.total" :page.sync="query.page" :limit.sync="query.limit" @pagination="getList" />
		</div>
		<Poptable :pType.async="pType" :ctype.async="todayType" ref="ptable" @dept="deptChange" @drug="drugChange" @doc="docChange" @phr="phrChange"></Poptable>
	</div>
</template>

<script>
	import Bluetable from "../../../components/Bluetable/index"
	import Poptable from "../components/poptable"
	import {ptc} from "@/api/systemport.js";
	export default {
		components:{Bluetable,Poptable},
		data () {
			return {
				todayType:"mz",//类型
				starttime:"",//开始时间
				endtime:"",//结束时间
				zd_drug_codes:"",//药品编码
				zd_drug_names:"",//药品名称
				zd_doc_codes:"",//医生编码
				zd_doc_names:"",//医生名称
				zd_dept_codes:"",//科室编码
				zd_dept_names:"",//科室
				zd_phr_codes:"",//药师编码
				zd_phr_names:"",//药师名称
				chooseType:"1",//1科室，2医生，3药品，4药师
				tHead:[
					{
						label:"序号",
						index:true
					},
					{
						prop:"name",
						label:"名称"
					},
					{
						prop:"tiJiaoCount",
						label:"提交数"
					},
					{
						prop:"yuShenBHlCount",
						label:"系统预审不合理数"
					},
					{
						prop:"yuShenBHlCountLv",
						label:"系统预审不合理率"
					},
					{
						prop:"lanjieCount",
						label:"系统拦截数"
					},
					{
						prop:"lanjieCountLv",
						label:"系统拦截率"
					},
					{
						prop:"chaoShiCount",
						label:"超时数"
					},
					{
						prop:"chaoShiCountLv",
						label:"超时率"
					},
					{
						prop:"yuShenXiuGaiCount",
						label:"系统预审后医生修改数"
					},
					{
						prop:"yuShenXiuGaiCountLv",
						label:"系统预审后医生修改率"
					},
					{
						prop:"shenHeCount",
						label:"药师候审数"
					},
					{
						prop:"shenHeCountLv",
						label:"药师候审率"
					},
					{
						prop:"phrGanYuCount",
						label:"药师干预数"
					},
					{
						prop:"phrGanYuCountLv",
						label:"药师干预率"
					},
					{
						prop:"phrFhSqCount",
						label:"药师复核双签"
					},
					{
						prop:"phrFhSqCountLv",
						label:"药师复核双签率"
					},
					{
						prop:"phrBfhSqCount",
						label:"药师不复核双签"
					},
					{
						prop:"sysGanYuCount",
						label:"系统自动干预数"
					},
					{
						prop:"sysGanYuXiuGaiCount",
						label:"系统自动干预后医生修改数"
					},
					{
						prop:"heGeCount",
						label:"合理数"
					},
					{
						prop:"heGeCountLv",
						label:"合理率"
					},
				],
				tableData: [],
				query:{
					total:0,
					page:1,
					limit:10
				},
				value: '',
				value1:"",
				input:"",
				pType:"11",
				style:"height: 60px;padding-top: 10px;",
				radio: 1
			}
		},
		mounted () {
			this.getList();
		},
		methods:{
			tab (val) {
				this.todayType = val;
				this.starttime="";
				this.endtime="";
				this.zd_drug_codes="";
				this.zd_drug_names="";
				this.zd_doc_codes="";
				this.zd_doc_names="";
				this.zd_dept_codes="";
				this.zd_dept_names="";
				this.zd_phr_codes="";
				this.zd_phr_names="";
				this.chooseType="1";
				this.query={
					page:1,
					limit:10,
					total:0
				};
				this.tableData=[];
				this.getList();
			},
			searchFun(){
				this.query={
					page:1,
					limit:10,
					total:0
				};
				this.tableData=[];
				this.getList();
			},
			deptChange(data){
				var names=[],codes=[];
				for(var i=0;i<data.length;i++){
					names.push(data[i].ksmc)
					codes.push(data[i].ksdm)
				}
				this.zd_dept_names=names.join(",");
				this.zd_dept_codes=codes.join(",");
			},
			drugChange(data){
				var names=[],codes=[];
				for(var i=0;i<data.length;i++){
					names.push(data[i].ypmc)
					codes.push(data[i].ypdm)
				}
				this.zd_drug_names=names.join(",");
				this.zd_drug_codes=codes.join(",");
			},
			docChange(data){
				var names=[],codes=[];
				for(var i=0;i<data.length;i++){
					names.push(data[i].ysmc)
					codes.push(data[i].ysdm)
				}
				this.zd_doc_names=names.join(",");
				this.zd_doc_codes=codes.join(",");
			},
			phrChange(data){
				var names=[],codes=[];
				for(var i=0;i<data.length;i++){
					names.push(data[i].real_name)
					codes.push(data[i].user_name)
				}
				this.zd_phr_names=names.join(",");
				this.zd_phr_codes=codes.join(",");
			},
			selectPop (val) {
				this.pType = val;
				this.$refs.ptable.show();
			},
			async getList(){
				let res =await this.$ptc.phrReportGYjson({
					type:this.todayType,
					starttime:this.starttime,
					endtime:this.endtime,
					zd_drug_codes:this.zd_drug_codes,
					zd_drug_names:this.zd_drug_names,
					zd_doc_codes:this.zd_doc_codes,
					zd_doc_names:this.zd_doc_names,
					zd_dept_codes:this.zd_dept_codes,
					zd_dept_names:this.zd_dept_names,
					zd_phr_codes:this.zd_phr_codes,
					zd_phr_names:this.zd_phr_names,
					chooseType:this.chooseType,
					page:this.query.page,
					pageSize:this.query.limit
				})
				if(res.total>0){
					this.query.total=res.total;
					this.tableData=res.rows;
				}
			},
			async exportFun(){
				// let res=await this.$ptc.gyDownloadExcel({
				// 	type:this.todayType,
				// 	HttpServletResponse:1,
				// });
				// console.log(res);
				let href=process.env.VUE_APP_BASE_API+":"+ptc+"/core/phar/phrReport/gy-download-excel?type="+this.todayType+"&HttpServletResponse=1";
				window.open(href, "_blank");
			}
		}
	}
</script>

<style lang="scss" scoped="scoped">
	body{
		background:#e6edf5;
	}
	.query{
		.tab{
			height:50px;
			line-height:50px;
			padding:0 20px;
			border-bottom:2px solid #e3ecf5;
			font-size:16px;
			color:#333;
			text-align:center;
			background:#fff;
			.tab_btn{
				width:100px;
				height:100%;
				cursor:pointer;
			}
			.tab_btn.active{
				color:#409eff;
				border-bottom:2px solid #409eff;
				height:50px;
			}
		}
		width:100%;
		height:100%;
		background:#e6edf5;
		.check{
			font-size:12px;
			display:flex;
			line-height:60px;
			background:#fff;
			text-align:center;
			.c_left{
				width:115px;
				float:left;
			}
			.c_right{
				overflow:hidden;
				color:#636365;
				border-left:1px solid #e6edf5;
				.c_tip{
					display:inline-block;
					width:100px;
					padding-right:10px;
					text-align:right;
				}
				.c_input{
					width:150px;
					height:40px;
					border:1px solid #dcdfe6;
					border-radius:4px;
					padding-left:5px;
				}
				.c_input::-webkit-input-placeholder {
					color: #dcdfe6;
				}
				.c_input::-ms-input-placeholder {
					color: #dcdfe6;
				}
				.c_input::-moz-input-placeholder {
					color: #dcdfe6;
				}
				.c_search{
					width:100px;
				}
				.c_searchbtn{
					display:inline-block;
					width:42px;
					height:25px;
					margin-left:4px;
					background:#28a4f4;
					color:#fff;
					font-size:12px;
					text-align:center;
					line-height:26px;
					border-radius:6px;
					cursor:pointer;
				}
				.c_checkbox{
					width:230px;
					height:40px;
					display:inline-block;
					margin-left:-12px;
				}
				.btn_clear{
					padding:0;
					width:70px;
					height:40px;
					line-height:40px;
				}
			}
		}
		.list_tip{
			font-size:14px;
			color:#29a4f2;
			padding:10px 18px;
		}
		.table_box{
			padding:0 18px;
		}
	}
	.el-checkbox__label{
		padding-left:5px;
	}
	.el-checkbox{
		margin-right:10px;
	}
</style>
